home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / asm / cm_int.exe / CM-MACS.LIB < prev    next >
Text File  |  1993-04-10  |  22KB  |  654 lines

  1.  
  2. ;   CM-MACS.LIB  -  By CFMartin  -  2/15/90
  3. ;
  4. ;   A Collection of Standard Assembly Macros written for use with the
  5. ;   Wolfware Assembler WASM, and the interrupt service provided by CM-INT.COM
  6. ;
  7. ;   General Notes:
  8. ;       1.  These macros are not necessarily compatible with any assembler
  9. ;           except WASM.
  10. ;       2.  Arguments for these macros are of two types, denoted by the
  11. ;           suffixes "_lab" and "_imm", for "label" and "immediate,"  based
  12. ;           on the expected most frequent usage.
  13. ;               a.  _lab indicates that the macro is looking for a
  14. ;                   label for a memory operand in the data segment.
  15. ;               b.  _imm indicates that the macro is looking for an immediate
  16. ;                   operand. To reference memory in the data segment, just
  17. ;                   enclose the operand label in brackets.
  18. ;       3.  Names and syntax of some macros will look very familiar to
  19. ;           C programmers, as they are patterned after standard C functions
  20.  
  21. ;   VIDEO/KEYBOARD MANAGEMENT
  22.  
  23. ;------------------
  24. vpage       macro   vpage_imm    ;selects video page
  25. ;------------------
  26. ;   vpage_imm   byte    video page number to be selected
  27. ;------------------
  28.             mov     ah,5
  29.             mov     al,vpage_imm
  30.             int     10h
  31.             endm
  32.  
  33. ;------------------
  34. vmode       macro   vmode_imm    ;sets video mode
  35. ;------------------
  36. ;   vmode_num   byte    video mode number
  37. ;------------------
  38.             mov     ah,0
  39.             mov     al,vmode_imm
  40.             int     10h
  41.             endm
  42.  
  43. ;------------------
  44. poscurs  macro row_imm,column_imm  ;positions cursor on active page (mode 2,3)
  45. ;------------------
  46. ;   row_imm,column_imm  bytes   0,0=upper left corner
  47. ;------------------
  48.         mov     ah,0Fh          ;get video state
  49.         int     10h
  50.         mov     ah,2            ;service 2 -- position cursor
  51.         mov     dh,row_imm      ;bh contains page
  52.         mov     dl,column_imm
  53.         int     10h             ;set cursor
  54.         endm
  55.  
  56. ;------------------
  57. clrscrn     macro   color_imm   ;clears active screen page (mode 2,3)
  58. ;------------------
  59. ;   color_imm       byte    attribute to clear screen with
  60. ;------------------
  61.         mov     ah,0Fh      ;get video state
  62.         int     10h
  63.         mov     al,bh       ;page
  64.         mov     ah,0
  65.         mov     bx,100h     ;256 paras per page modes 2 & 3
  66.         mul     bx
  67.         add     ax,0B800h   ;seg of page 0
  68.         mov     es,ax
  69.         mov dl,color_imm
  70.         mov di,0
  71.         mov ah,dl
  72.         mov cx,2000
  73.         mov al,20h      ;blank
  74.         cld
  75.         rep
  76.         stosw
  77.         endm
  78.  
  79. ;------------------
  80. pause    macro   key_name_imm   ;pauses until the named key is pressed
  81. ;------------------
  82. ;   key_name_imm    byte    key to wait for
  83. ;------------------
  84.         mov     bl,byte key_name_imm
  85.         mov     bh,00h
  86.         int     0C0h
  87.         endm
  88.  
  89.  
  90. ;------------------
  91. print   macro   str_lab     ;print string at current cursor pos on active page
  92. ;------------------
  93. ;   str_lab     byte        label of ASCIIZ string to print
  94. ;------------------
  95.         lea     si,str_lab
  96.         mov     bh,01h
  97.         int     0C0h
  98.         endm
  99.  
  100. ;------------------
  101. input   macro   str_lab   ;input string to <Rtn> with echo to active page
  102. ;------------------
  103. ;   str_lab     byte        label of ASCIIZ destination string
  104. ;------------------
  105.             lea     si,str_lab
  106.             mov     bh,02h
  107.             int     0C0h
  108.             endm
  109.  
  110. ;------------------
  111. scan    macro   prompt_lab,data_lab,data_len_imm
  112. ;------------------
  113. ;   prompt_lab      byte        label of ASCIIZ prompt string
  114. ;   data_lab        byte        label of ASCIIZ dest string for input
  115. ;   data_len_imm    byte        unsigned length of dest string
  116. ;   (Use no filtering, no blank stripping, window color 0Fh)
  117. ;------------------
  118.         lea     si,prompt_lab
  119.         lea     di,data_lab
  120.         mov     al,data_len_imm
  121.         mov     ah,0        ;no input data filtering
  122.         mov     cl,0        ;no blank stripping
  123.         mov     ch,0Fh      ;window color=hi intens wh, blk bkgd
  124.         mov     bx,300h     ;upper and lower case accepted
  125.         int     0C0h
  126.         endm
  127.  
  128. ;------------------
  129. lprint macro str_lab
  130. ;------------------
  131. ; Prints ASCIIZ string at ds:offset str_lab to parallel printer
  132. ;------------------
  133.  
  134.  mov cx,-1
  135.  lea si,str_lab
  136.  mov bh,4
  137.  int 0C0h
  138.  endm
  139.  
  140. ;------------------
  141. lprintc macro ctrl_str_lab
  142. ;------------------
  143. ; Prints printer control string at ds:offset ctrl_str_lab to parallel printer
  144. ; First byte of control string is length; remainder is string
  145. ;------------------
  146.  
  147.  mov cl,[ctrl_str_lab]
  148.  xor ch,ch
  149.  lea si,ctrl_str_lab
  150.  inc si
  151.  mov bh,4
  152.  int 0C0h
  153.  endm
  154.  
  155.  
  156.  
  157. ;   NUMERICAL CONVERSION
  158.  
  159. ;------------------
  160. ltoa    macro   dw_lab,str_lab  ;convert 32-bit number to decimal ASCIIZ string
  161. ;------------------
  162. ;   dw_lab      double word     32-bit number to be converted
  163. ;   str_lab     byte            label of ASCIIZ dest string in ds
  164. ;------------------
  165.             lea     si,str_lab
  166.             mov     ax,[offset dw_lab]      ;low order 16 bits
  167.             mov     dx,[offset dw_lab+2]    ;high order 16 bits,
  168.                                             ;including sign (bit 31)
  169.             mov     bl,0                    ;decimal return
  170.             mov     bh,06h
  171.             int     0C0h
  172.             endm
  173.  
  174. ;------------------
  175. ltoa2   macro   dw_lab,str_lab,base_imm     ;convert with base option
  176. ;------------------
  177. ;   dw_lab      double word     32-bit number to be converted
  178. ;   str_lab     byte            label of ASCIIZ dest string in ds
  179. ;   base_imm    byte            dec=0,hex=1,oct=2,bin=3
  180. ;------------------
  181.             lea     si,str_lab
  182.             mov     ax,[offset dw_lab]    ;low order 16 bits
  183.             mov     dx,[offset dw_lab+2]  ;high order 16 bits,
  184.                                             ;including sign (bit 31)
  185.             mov     bl,base_imm
  186.             mov     bh,06h
  187.             int     0C0h
  188.             endm
  189. ;------------------
  190. atol    macro   dw_lab,str_lab  ;conv string to 32-bit d-word
  191. ;------------------
  192. ;   dw_lab          double word     32-bit number to be converted
  193. ;   str_lab         byte            label of ASCIIZ source string in ds
  194. ;------------------
  195.             lea     si,str_lab
  196.             mov     bh,07h
  197.             int     0C0h
  198.             mov     [offset dw_lab],ax    ;low order 16-bits
  199.             mov     [offset dw_lab+2],dx  ;high order 16-bits
  200.             endm
  201.  
  202. ;------------------
  203. itoa    macro   w_lab,str_lab       ;conv signed 16-bit word to dec string
  204. ;------------------
  205. ;   w_lab           word        signed 16-bit number to be converted
  206. ;   str_lab         byte        label of ASCIIZ dest string in ds
  207. ;------------------
  208.             lea     si,str_lab
  209.             mov     ax,[offset w_lab] ;16-bit signed no.
  210.             cwd                     ;extend to d-word
  211.             mov     bl,0            ;return decimal
  212.             mov     bh,06h
  213.             int     0C0h
  214.             endm
  215.  
  216. ;------------------
  217. itoa2   macro   w_lab,str_lab,base_imm  ;conv signed 16-bit word to string
  218. ;------------------
  219. ;   w_lab           word        signed 16-bit number to be converted
  220. ;   str_lab         byte        label of ASCIIZ dest string in ds
  221. ;   base_imm        byte        dec=0,hex=1,oct=2,bin=3
  222. ;------------------
  223.             lea     si,str_lab
  224.             mov     ax,[offset w_lab] ;16-bit signed no.
  225.             cwd                     ;extend to d-word
  226.             mov     bl,base_imm
  227.             mov     bh,06h
  228.             int     0C0h
  229.             endm
  230. ;------------------
  231. atoi    macro   w_lab,str_lab   ;conv string to signed 16-bit
  232. ;------------------
  233. ;   w_lab           word        signed 16-bit number to be converted
  234. ;   str_lab         byte        label of ASCIIZ source string in ds
  235. ;------------------
  236.             lea     si,str_lab
  237.             mov     bh,07h
  238.             int     0C0h
  239.